<template>
	<view class="container">
		<sl-filter :independence="true" :color="titleColor" :themeColor="themeColor" :menuList.sync="menuList" @result="result" />
		<view class="text">
			<text>{{filterResult}}</text>
		</view>
		<scroll-view style="height: 1010rpx" class="moments" scroll-y="true" refresher-enabled="true" :refresher-triggered="triggered"
		 :refresher-threshold="100" refresher-background="#F5F5F5" @refresherpulling="onPulling" @refresherrefresh="onRefresh"
		 @refresherrestore="onRestore" @refresherabort="onAbort">
			<moments @showMask="toggleMask('show')" @tap="goStation" ref='a' />
		</scroll-view>
		<ygc-comment ref="ygcComment" :placeholder="'发布评论'" @pubComment="pubComment"></ygc-comment>
	</view>
</template>

<script>
	import slFilter from '@/components/sl-filter/sl-filter.vue';
	import moments from '@/components/moments.vue';
	import service from '../../service.js'

	export default {
		components: {
			slFilter,
			moments
		},
		data() {
			return {

			}
		},
		onLoad() {
			service.checkSessionKey().then((isFirstLogin) => {
				if(isFirstLogin){
				}else{
					uni.showModal({
						title: '温馨提示',
						content: '此时此刻需要您登录喔~',
						confirmText: "登录",
						cancelText: "取消",
						success: (res)=> {
							//点击确定
							if (res.confirm) {
								uni.navigateTo({
									url:"../login/login"
								});
							}else{
								//点击取消
								uni.switchTab({
									url: '/pages/index/index',
									success: function () {
										console.log('switch success');
									},
									fail: function (err) {
										console.log('switchTab fail', err);
									}
								});
							}
						}
					})
				}
			})
			
			// this.checkStorage();
		},
		onPullDownRefresh() {

		},
		methods: {
			init() {
				
			},
			checkStorage() {
				const flag = uni.getStorageSync('isFirstLogin');
				console.log(flag)
				if (!flag) {
					uni.showModal({
						title: '提示',
						content: '还未登录，请登录',
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: '../login/login'
								})
							}
						}
					})
				} else {
					uni.switchTab({
						url: 'pages/index/index'
					})
				}
			},
			result(val) {
				console.log('filter_result:' + JSON.stringify(val));
				this.filterResult = JSON.stringify(val, null, 2)
			},
			toggleMask(type) {
				this.$refs.ygcComment.toggleMask(type);
			},
			pubComment(commentContent1) {
				this.$refs.ygcComment.toggleMask();
				console.log(commentContent1);
				this.commentContent = commentContent1;
				this.$refs.ygcComment.content = '';
			},
			// 跳转到个人站首页
			goStation() {
				this.$refs.a.goStation()
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f0f0f0;
	}

	.moments {
		padding: 20rpx 0;
		box-sizing: border-box;
		border-radius: 20rpx;
	}
</style>
